const arrayPrototype = Array.prototype;

export const newArrayObserve = Object.create(arrayPrototype);

const arrayMethods = [
    'push',
    'pop',
    'shift',
    'unshift',
    'splice',
    'reverse',
    'sort'
]

arrayMethods.forEach(method => {
    newArrayObserve[method] = function (...args) {
        const result = arrayPrototype[method].call(this, ...args)
        let inserted;
        switch (method) {
            case 'push':
            case 'unshift':
                inserted = [...args];
                break;
            case 'splice':
                inserted = args.slice(2)


            default:
                break;
        }

        if (inserted) {
            console.log(this);
            this.__ob__.observeArray(inserted)
        }
        return result;
    }
})
